/*
 ============================================================================
 Name        : c001.c
 Author      : zhengfei
 Version     :
 Copyright   : Your copyright notice
 Description : Hello World in C, Ansi-style
 ============================================================================
 */

#include <stdio.h>
#include <stdlib.h>

void printarray(int *a, int);
void inv(int a[], int);
void inv2(int *a, int);
void insertSort(int *a, int);
int max(int, int);

int main(void) {
	/*
	 int *p, i, a[9];
	 p = a;
	 for (i = 0; i < 9; i++) {
	 scanf("%d", p++);
	 }
	 p = a;
	 printarray(a, 9);
	 inv2(a, 9);
	 p = a;
	 printarray(a, 9);
	 insertSort(a, 9);
	 printarray(a, 9);*/
	int a, b, c;
	int (*p)(int, int);
	p = max;
	printf("enter number a and b:");
	scanf("%d %d", &a, &b);
	c = (*p)(a, b);
	printf("c=%d", c);
	return EXIT_SUCCESS;
}

void printarray(int *a, int n) {
	int i;
	int *p = a;
	for (i = 0; i < n; i++) {
		printf("%d ", *(p++));
	}
	printf("\n");
}

void inv(int a[], int n) {
	printf("call inv()\n");
	int i, j, temp, m = (n - 1) / 2;
	for (i = 0; i <= m; i++) {
		j = n - 1 - i;
		printf("i=%d j=%d\n", i, j);
		temp = a[i];
		a[i] = a[j];
		a[j] = temp;
	}
}

void inv2(int *a, int n) {
	printf("call inv2()\n");
	int temp, *i, *j, *p, m = (n - 1) / 2;
	i = a;
	j = a + n - 1;
	p = a + m;
	for (; i <= p; i++, j--) {
		temp = *i;
		*i = *j;
		*j = temp;
	}
}

void insertSort(int *array, int len) {
	int i, j, temp;

	for (i = 1; i < len; i++) {
		temp = array[i];
		for (j = i - 1; j >= 0; j--) {
			if (array[j] > temp) {
				array[j + 1] = array[j];
				printarray(array, len);
			} else {
				break;
			}
		}
		array[j + 1] = temp;
		printarray(array, len);
	}
}

int max(int a, int b) {
	return a > b ? a : b;
}
